package com.test.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Configuration
public class SessionInterceptor implements HandlerInterceptor {
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		System.out.println(request.getRequestURI());
		System.out.println(request.getContextPath());
		if(request.getSession().getAttribute("user")==null){//没有登录
			response.sendRedirect("/");//如果没有登录信息，则跳转到首页(登录页面)
			return false;
		}
		return true;
	}
}
